#!/bin/sh

if [ -z $1 ];then
   hive_db=default
else
   hive_db=$1
fi

if [ -z $2 ];then
   create_time=`date  "+%Y-%m-%d %H-%M-%S"`
else
   create_time=$2
fi

hiveconfig=$(cat <<"EOF" /home/hdfs/parquet_shell/hive_parquet_scripts/hive.config
EOF
)

sql_suffix=$(cat <<EOF 
INSERT INTO TABLE ${hive_db}.navinfo_parquet_d00a PARTITION (part_time) SELECT latitude,longitude,originallat,originallng,height,direction,gpsdate,version,engineintakemanifoldpressure,engineintakemanifoldtemperature,enginecoolanttemperature,fueltemperature,ambienttemperature,instrumentspeed,rotation,servicebrakecircuit1airpressure,servicebrakecircuit2airpressure,fanspeed,accumulatedmileage,subtotalmileage,acceleratorpedalposition,currentrotationload,servicebrake,escinstrumentlightsignal,absactivationstatus,escfullactivation,escbrakelightrequestsignal,antirolloverengine,antirolloverbrake,directioncontrolengine,directioncontrolbrake,escactivatetrailer,steeringwheelanglesensortype,exhaustbrakingstate,incylinderbrake2status,incylinderbrake1status,steeringwheelturnsnumber,auxiliarybrakegear,steeringwheelangle,yawrate,lateralacceleration,longitudinalacceleration,brakepedaltravel,frontwheelspeed,rearaxleoneleftwheelspeed,rearaxleonerightwheelspeed,rearaxletwoleftwheelspeed,rearaxletworightwheelspeed,erc1actualtorqueretarder,erc1maximumtorqueretarder,erc1actualtorqueengine,erc1maximumtorqueengine,terminalid,serialnumber,retransmissionpackets,downshiftReminder,constantSpeedGear,engineAirFilterPressureDifference,standingCircuitPressureIndication, '${create_time}', part_time FROM ${hive_db}.navinfo_stage_d00a distribute by part_time ;
EOF
)

sql="${hiveconfig}${sql_suffix}"
############  execute begin   ###########
hive --hiveconf "tez.queue.name=hive" -S -e "$sql"
#echo $sql
